package fun.shuofeng.juc.completableFuture;

import java.sql.Time;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author 朔风
 * @date 2024-02-29 21:41
 */
public class CompletableFutureFastDemo {
    public static void main(String[] args) {

        CompletableFuture<String> playA = CompletableFuture.supplyAsync(() -> {
            System.out.println("A come in");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "playA";
        });
        CompletableFuture<String> playB = CompletableFuture.supplyAsync(() -> {
            System.out.println("B come in");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "playB";
        });

        CompletableFuture<String> completableFuture = playA.applyToEither(playB, result -> {
            return result + " is winter";
        });

        System.out.println(Thread.currentThread().getName()+"-----"+completableFuture.join());
    }
}
